package com.songVersion.services.impl;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.songVersion.model.Cover;
import com.songVersion.model.ThumbnailCache;
import com.songVersion.model.Version;
import com.songVersion.services.VersionManager;

public class VersionManagerImpl extends CountingManagerImpl<Version> implements VersionManager
{

	private Version theVersion;
	
	@Override
	protected void addHit(Version t)
	{
		t.setHits(t.getHits() + 1);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	protected Version doLoadBean(PersistenceManager pm)
	{
		Query query = pm.newQuery(Version.class);
		query.setFilter("songName == nameParam && songAuthor == authorParam");
		query.declareParameters("String nameParamm, String authorParam");
		List<Version> l = (List<Version>) query.execute(theVersion.getSongName(), theVersion.getSongAuthor());
		if (l == null || l.size() == 0)
			return null;
		else
			return l.get(0);
	}

	@Override
	protected void initResultList(List<Version> l)
	{
		for (Version c: l)
		{
			ThumbnailCache t = c.getThumb();

		}
	}
	@Override
	protected Version newBean()
	{
		Version v = new Version(theVersion.getSongName(), theVersion.getSongAuthor(), theVersion.getThumb());
		return v;
	}

	@Override
	public void init()
	{
		this.t = new Version("", "", null);
		
	}

	public Version getTheVersion()
	{
		return theVersion;
	}

	public void setTheVersion(Version theVersion)
	{
		this.theVersion = theVersion;
	}

}
